package lapsnake.model.expr;

import lapsnake.model.*;
import lapsnake.model.data.*;
import lapsnake.model.misc.LapComprehension;
import lapsnake.py.ast.ASTHelperFactory; 
import lapsnake.ui.JTreeLabel;

import java.awt.Component;
import java.beans.PropertyVetoException;

import org.python.antlr.ast.*;

/**Wrapper class with helper functions for GeneratorExp nodes*/
public class LapGeneratorExp extends LapExpression {
	public final SingleChild<LapExpression> element = new SingleChild<>(this, LapExpression.class);
	public final ChildList<LapComprehension> generators = new ChildList<>(this, LapComprehension.class, false); // TODO find out if optional
	
	public LapGeneratorExp(PyAST pyAST, ChildField<? super LapGeneratorExp> parent, GeneratorExp node) throws PropertyVetoException {
		super(pyAST, parent, node);
		
		ASTHelperFactory.makeHelper(pyAST, element, node.getInternalElt());
		ASTHelperFactory.makeHelpers(pyAST, generators, node.getInternalGenerators());
		buildTextNodes(node);
	}
	
	@Override
	protected Component getFillerComponent(int childIndex,
		ChildField<?> childField)
	{
		if(childField == element)
			return new JTreeLabel("Generate", false);
		else
			return new JTreeLabel("from", false);
	}
}
